package com.wgchao.amc.mapstruct.mapper.expand;

import com.wgchao.amc.entity.autho.SysAuthoUser;
import com.wgchao.amc.entity.autho.SysAuthoUserFunc;
import com.wgchao.amc.mapstruct.DTOMapper;
import com.wgchao.amc.mapstruct.dto.SysAuthoUserDTO;
import com.wgchao.amc.mapstruct.mapper.SysAuthoUserFuncMapper;
import com.wgchao.amc.mapstruct.mapper.SysAuthoUserMapper;
import com.wgchao.amc.repository.autho.SysAuthoUserFuncRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName: SysAuthoUserMapperExpand
 * @author: wgchao
 * @createTime: 2019/10/31 10:51 AM
 * @Description: TODO
 */
@Component
public class SysAuthoUserMapperExpand implements DTOMapper<SysAuthoUser, SysAuthoUserDTO> {
    @Autowired
    private SysAuthoUserMapper authoUserMapper;
    @Autowired
    private SysAuthoUserFuncMapper authoUserFuncMapper;
    @Autowired
    private SysAuthoUserFuncRepository authoUserFuncRepository;

    @Override
    public SysAuthoUser toEntity(SysAuthoUserDTO sysAuthoUserDTO) {
        return authoUserMapper.toEntity(sysAuthoUserDTO);
    }

    @Override
    public SysAuthoUserDTO toDTO(SysAuthoUser sysAuthoUser) {
        return authoUserMapper.toDTO(sysAuthoUser);
    }

    @Override
    public List<SysAuthoUser> toEntity(List<SysAuthoUserDTO> sysAuthoUserDTOS) {
        return authoUserMapper.toEntity(sysAuthoUserDTOS);
    }

    @Override
    public List<SysAuthoUserDTO> toDTO(List<SysAuthoUser> sysAuthoUsers) {
        return authoUserMapper.toDTO(sysAuthoUsers);
    }

    public SysAuthoUserDTO getFuncInfo(SysAuthoUserDTO authoUserDTO){
        List<SysAuthoUserFunc> authoRoleFuncs = authoUserFuncRepository.findAllByAuId(authoUserDTO.getId());
        if(authoRoleFuncs!=null && !authoRoleFuncs.isEmpty()){
            authoUserDTO.setFuncInfos(authoUserFuncMapper.toDTO(authoRoleFuncs));
        }
        return authoUserDTO;
    }
}
